Código fuente de 'Operaciones con cadenas.asp'

<html>
<head>
<title>Operaciones con cadenas - Códigos asp, programacion asp, descargas asp, rutinas asp</title>
</head>
<p align="center"><b><font size="3">Operaciones con cadenas</font></b>
<body style="font-family: Arial; font-size: 9pt">
</p>


<br><br><b>Aquí tienes cuatro funciones para operar con cadenas (ver 
implementación en código 
fuente):<br>
</b><br>
<u>SearchString</u><br>
- Busca una cadena dentro de otra cadena sin tener en cuenta mayúsculas o 
minúsculas.<br>
- Devuelve TRUE si la cadena se encuentra y FALSE en caso contrario.


    <%
    Function SearchString(sts, stf)
    	' Convert both strings to lower case and see if the search string is within the string being searched
    	If InStr(LCase(sts), LCase(stf)) > 0 Then
    		' Returns true if the string is found
    		SearchString = true
    	Else
    		' Returns false if the string isn't found
    		SearchString = false
    	End If
    End Function
    %>
    
<br><br><u>WordCount</u><br>
- Cuenta el número de palabras en una cadena y devuelve el número total.


    <%
    Function WordCount(stringPassed)
    	' Set up global variables
    	Dim post, spaceCount
    	pos = 1
    	spaceCount = 0
    	' Iterates through every character in the string
    	While NOT pos = Len(stringPassed)
    	' Test if the current character is a space and if it has a space before it
    		If Mid(stringPassed, pos, 1) = " " Then
    		' Checks if the loop is at the beginning of the string
    		If NOT pos = 1 Then
    				' Checks to see if the character before the space is a space
    				If NOT Mid(stringPassed, pos-1, 2) = " " Then
    	
    					' Add 1 to spacecount if space found without a space before it
    					spaceCount = spaceCount+1
    				End If
    			End If
    		End If
    	' Increment string position by 1
    	pos = pos+1
    	Wend
    	' Calculate number of words in string and return
    	WordCount = spaceCount+1
    End Function
    %>
    
<br><br><u>TitleCase</u><br>
- Convierte la cadena pasada en una cadena tipo "título".



    <%
    Function TitleCase(stringPassed)
    	' Set up global variables
    	Dim post, tcString
    	pos = 1
    	tcString = ""
    	' Iterate through every character in the string
    	While NOT pos = Len(stringPassed)+1
    		' Checks to see if the current character is a space
    		If NOT Mid(stringPassed, pos, 1) = " " Then
    			' Checks if the loop is at the beginning of the string
    			If NOT pos = 1 Then
    				' Checks if the character before the current character is a space
    				If Mid(stringPassed, pos-1, 1) = " " Then
    					' Add current character to tcString in uppercase
    					tcString = tcString+UCase(Mid(stringPassed, pos, 1))
    				Else
    					' Add current character to tcString in lowercase
    					tcString = tcString+LCase(Mid(stringPassed, pos, 1))
    				End If
    			Else
    				' Add current current character to tcString in uppercase
    				tcString = tcString+UCase(Mid(stringPassed, pos, 1))
    			End If
    		Else
    			' Adds current character to tcString
    			tcString = tcString+Mid(stringPassed, pos, 1)
    		End If
    	' Increment current string position by 1
    	pos = pos+1
    	Wend
    	' Return tcString
    	TitleCase = tcString
    End Function
    %>
    
<br><br><u>RemoveSigns<br>
</u>- Elimina todos los símbolos de la cadena (puede también eliminar espacios).

    <%
    Function RemoveSigns(stringPassed, cleanSpaces)
    	' Set up global variables
    	Dim cleanString
    	cleanString = ""
    	' Replace signs with nothing
    	cleanString = Replace(stringPassed, "!", "")
    	cleanString = Replace(cleanString, """", "")
    	cleanString = Replace(cleanString, "£", "")
    	cleanString = Replace(cleanString, "$", "")
    	cleanString = Replace(cleanString, "%", "")
    	cleanString = Replace(cleanString, "^", "")
    	cleanString = Replace(cleanString, "&", "")
    	cleanString = Replace(cleanString, "*", "")
    	cleanString = Replace(cleanString, "(", "")
    	cleanString = Replace(cleanString, ")", "")
    	cleanString = Replace(cleanString, "-", "")
    	cleanString = Replace(cleanString, "_", "")
    	cleanString = Replace(cleanString, "+", "")
    	cleanString = Replace(cleanString, "=", "")
    	cleanString = Replace(cleanString, "[", "")
    	cleanString = Replace(cleanString, "]", "")
    	cleanString = Replace(cleanString, "{", "")
    	cleanString = Replace(cleanString, "}", "")
    	cleanString = Replace(cleanString, ";", "")
    	cleanString = Replace(cleanString, ":", "")
    	cleanString = Replace(cleanString, "@", "")
    	cleanString = Replace(cleanString, "'", "")
    	cleanString = Replace(cleanString, "#", "")
    	cleanString = Replace(cleanString, "~", "")
    	cleanString = Replace(cleanString, "<", "")
    	cleanString = Replace(cleanString, ">", "")
    	cleanString = Replace(cleanString, ",", "")
    	cleanString = Replace(cleanString, ".", "")
    	cleanString = Replace(cleanString, "?", "")
    	cleanString = Replace(cleanString, "/", "")
    	cleanString = Replace(cleanString, "\", "")
    	cleanString = Replace(cleanString, "|", "")
    	cleanString = Replace(cleanString, "`", "")
    	cleanString = Replace(cleanString, "¬", "")
    	cleanString = Replace(cleanString, "¦", "")
    	' Replace spaces if required
    	If cleanSpaces = 1 Then
    		cleanString = Replace(cleanString, " ", "")
    	End If
    	' Return cleanString
    	RemoveSigns = cleanString
    End Function
    %>
    
    </body></html>